# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

source "$(dirname ${BASH_SOURCE[0]})"/../mingw-w64-PKGBUILD-common/kde-frameworks
_realname=kimageformats
pkgbase="mingw-w64-${_realname}"
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=6.14.0
pkgrel=1
pkgdesc="Plugins to allow QImage to support extra file formats (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: kimageformats'
  "cpe: cpe:/a:kde:kimageformats"
)
msys2_repository_url='https://invent.kde.org/frameworks/kimageformats/'
url='https://community.kde.org/Frameworks/'
license=('spdx:LGPL-2.0-or-later')
depends=(
  "${MINGW_PACKAGE_PREFIX}-qt6-base"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-extra-cmake-modules"
  "${MINGW_PACKAGE_PREFIX}-karchive"
  "${MINGW_PACKAGE_PREFIX}-libavif"
  "${MINGW_PACKAGE_PREFIX}-libheif"
  "${MINGW_PACKAGE_PREFIX}-libjxl"
  "${MINGW_PACKAGE_PREFIX}-libraw"
  "${MINGW_PACKAGE_PREFIX}-ninja"
  "${MINGW_PACKAGE_PREFIX}-openexr"
  "${MINGW_PACKAGE_PREFIX}-openjpeg2"
  "${MINGW_PACKAGE_PREFIX}-qt6-tools"
)
optdepends=(
  "${MINGW_PACKAGE_PREFIX}-imath: EXR format support"
  "${MINGW_PACKAGE_PREFIX}-karchive: plugin for Krita and OpenRaster images"
  "${MINGW_PACKAGE_PREFIX}-libavif: AVIF format support"
  "${MINGW_PACKAGE_PREFIX}-libheif: HEIF format support"
  "${MINGW_PACKAGE_PREFIX}-libjxl: JPEG-XL format support"
  "${MINGW_PACKAGE_PREFIX}-libraw: RAW format support"
  "${MINGW_PACKAGE_PREFIX}-openexr: EXR format support"
  "${MINGW_PACKAGE_PREFIX}-openjpeg2: JPEG 2000 format support"
)
groups=("${MINGW_PACKAGE_PREFIX}-kf6")
source=("https://download.kde.org/stable/frameworks/${pkgver%.*}/${_realname}-${pkgver}.tar.xz"{,.sig})
sha256sums=('3a0f81be25e9a0eab7dc1373bc56480abcb3041ca1a5a8c7f0d6d52d221d5449'
            'SKIP')
validpgpkeys=(
  'E0A3EB202F8E57528E13E72FD7574483BB57B18D' # Jonathan Esk-Riddell <jr@jriddell.org>
  '90A968ACA84537CC27B99EAF2C8DF587A6D4AAC1' # Nicolas Fella <nicolas.fella@kde.org>
)

build() {
  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  _kde_build_env
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    "${MINGW_PREFIX}"/bin/cmake.exe \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${_KDE_INSTALL_DIRS[@]}" \
      -DBUILD_QCH=OFF \
      -DBUILD_TESTING=OFF \
      -DKIMAGEFORMATS_HEIF=ON \
      "${_extra_config[@]}" \
      -S "${_realname}-${pkgver}" \
      -B "build-${MSYSTEM}"

  "${MINGW_PREFIX}"/bin/cmake.exe --build "build-${MSYSTEM}"
}

package() {
  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install "build-${MSYSTEM}"
}
